function pi(el){
    return parseInt(el);
}
function sendData(url,data,succ,err,type,dataType,conentType){
    if(!type){type="POST"}
    if(!err){err=isError}
    if(!url){throw new Error("url is not find...");}
    if(!dataType){dataType="JSON"}
    if(!conentType){conentType="application/x-www-form-urlencoded"}
    function isError(){
        alert("请求出错，请重试。");
    }
    $.ajax({
        type:type,
        dataType:dataType,
        url: url, //必填
        data:data,
        success:succ,
        error:err
    });
}
function yxSendData(url,data,succ,err,type,dataType,conentType){
    if(!type){type="POST"}
    if(!url){throw new Error("url is not find...");}
    if(!dataType){dataType="JSON"}
    if(!conentType){conentType="application/x-www-form-urlencoded"}
    var xhr = new XMLHttpRequest();
    xhr.open(type, url, true);
    xhr.setRequestHeader("Content-type",conentType);
    xhr.onreadystatechange = function(){
        var XMLHttpReq = xhr;
        if (XMLHttpReq.readyState == 4) {
            if (XMLHttpReq.status == 200) {
                var text = XMLHttpReq.responseText;
                succ(text);
            }
        }
    };
    xhr.send(data);
}
//获取验证码
function _getCode(el,time,back,interval,msgBox,bgColor,color){
    var code=$(el);
    if(!time){time=30}
    if(!interval){interval=1000}
    if(!bgColor){bgColor="#aaa"}
    if(!color){color="#fff"}
    showMsg(msgBox,"验证码已改善..","red");
    var time1=time;
    var codeback=code.css("background-color");
    var codeColor=code.css("color");
    code.css("background-color",bgColor);
    code.css("color",color);
    code.unbind("click",back);
    time1--;
    code.html("剩余"+time1+"s");
    code.addClass("msgs1");
    var t=setInterval(function  () {
        time1--;
        code.html("剩余"+time1+"s");
        if (time1==0) {
            clearInterval(t);
            code.html("获取验证码");
            code.removeClass("msgs1");
            code.css("background-color",codeback);
            code.css("color",codeColor);
            code.bind("click",back);
            showMsg(msgBox,"验证码已发送，5分钟有效..","red");
        }
    },interval)
}
function showMsg(el,text,color){
    if(!color){color="red"}
    $(el).css("display","block");
    $(el).html(text);
    $(el).css("color",color);
}
//手机号码
function checkMobile(ph){
    ph = ph.toString();
    // var isPhone =/^([0-9]{3,4}-)?\d{7,8}$/;
    // var isMob=/^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/g;
    // console.log(isPhone.test(ph));
    // console.log(isMob.test(ph));
    // if(isMob.test(ph)||isPhone.test(ph)){
    //     return true;
    // }else{
    //     return false;
    // }
    if(/^\d{7,12}$/g.test(ph)){
        return true;
    }else{
        return false;
    }
}
//验证QQ号
function checkQQ(qq){
    if(/^\d{5,11}$/g.test(qq)){
        return true;
    }else{
        return false;
    }
}

function checkMail(yx){
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(filter.test(yx)){
        return true;
    }else{
        return false;
    }
}

function changePwd(newPwd,confim){
    var newPwd=$(newPwd).val();
    var confim=$(confim).val();
    if(newPwd.trim()!==confim.trim()){
        return false;
    }
    return true;
}
function checkPwd(newPwd,confim){
    if(newPwd!==confim){
        return false;
    }
    return true;
}
/*可定制的弹出框*/
function showMobileAlert(title,lbtn,rbtn,operation,succ,font){
    var once=false;
    if(!title){title='是否退出?'}
    if(!lbtn && lbtn!=='null'){lbtn='是'}
    if(!rbtn && rbtn!=='null'){rbtn='否'}
    if(lbtn==='null'){ lbtn='';once=true;}
    if(rbtn==='null'){rbtn='',once=true}
    var flag=document.createDocumentFragment();
    var style=document.createElement('style');
    style.innerHTML="#mobileAlert{width:100%;height:100%;position:fixed;top:0;left:0;background-color:rgba(0,0,0,.5);z-index:999999;display:none}\
    #mobileAlert>.box{width:90%;max-width:400px;background-color:#fff;margin:0 auto;position:absolute;top:200px;left:50%;border-radius:8px;transform:translateX(-50%)}\
    #mobileAlert>.box>.title{padding:30px 0;text-align:center;font-size:16px;font-family:'微软雅黑','microsoft YaHei'}\
    #mobileAlert>.box>ul{border-top:1px solid #F3F3F3;list-style:none;padding:0px;}\
    #mobileAlert>.box>ul:after{content:'';display:table;clear:both;}\
    #mobileAlert>.box>ul>li{float:left;width:50%;height:40px;line-height:40px;text-align:center;font-size:16px}\
    #mobileAlert>.box>ul>li>a{font-family:'微软雅黑','microsoft YaHei'}#mobileAlert>.box>#show2>li{width:100%}\
    #mobileAlert .box > ul.center>li{width:100%} ";
    flag.appendChild(style);
    var huosdk_div=document.createElement('div');
    huosdk_div.id='mobileAlert';
    huosdk_div.innerHTML='<div class="box">\
        <p class="title">确定退出？</p>\
        <ul class='+(once==false?"":"center")+'>\
            <li class="lbtn" style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;g:border-box;border-right:1px solid #F3F3F3">\
                <a href="#">是</a>\
                </li>\
            <li class="rbtn"><a href="#">否</a></li>\
        </ul>\
        </div>';

    flag.appendChild(huosdk_div);
    document.body.appendChild(flag);
    document.querySelector("#mobileAlert").style.fontSize=font;
    document.querySelector("#mobileAlert .title").innerHTML=title;
    document.querySelector("#mobileAlert .lbtn a").innerHTML=lbtn;
    document.querySelector("#mobileAlert .rbtn a").innerHTML=rbtn;
    if(operation=='do'){
        document.querySelector("#mobileAlert .rbtn").style.display='none';
        document.querySelector("#mobileAlert .lbtn").onclick=function(){
            document.querySelector("#mobileAlert").style.display='none';
            succ();
        };
    }else{
        document.querySelector("#mobileAlert .lbtn").style.display='none';
        document.querySelector("#mobileAlert .rbtn").onclick=function(){
            document.querySelector("#mobileAlert").style.display='none';
            succ();
        };
    }
    document.querySelector("#mobileAlert").style.display='block';
}
//标签页
function tabs(el,targetEl,way){
    $(el).each(function(i){
        this.index=i;
        $(this).click(function(){
            $(this).addClass("active").siblings().removeClass("active");
            if(way=="fade"){
                $(targetEl).eq(this.index).siblings().hide();
                $(targetEl).eq(this.index).fadeIn();
            }else{
                $(targetEl).eq(this.index).show().siblings().hide();
            }
        })
    })
}
//hover标签页
function hoverTabs(el,targetEl,way){
    $(el).each(function(i){
        this.index=i;
        $(this).hover(function(){
            $(this).addClass("active").siblings().removeClass("active");
            if(way=="fade"){
                $(targetEl).eq(this.index).siblings().hide();
                $(targetEl).eq(this.index).fadeIn();
            }else{
                $(targetEl).eq(this.index).show().siblings().hide();
            }
        })
    })
}
//	预览图片
function seeImg(el,imgBox,succ){
    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }
    el.on("change",function(){
        var objUrl = getObjectURL(el[0].files[0]);
        if (objUrl) {
            imgBox.attr("src", objUrl);
            imgBox.attr("class", "fileImg");
            succ();
        }
    })
}
//高亮标签
function highLight(el,className){
    $(el).each(function(){
        $(this).on('click',function(){
            $(this).addClass(className).siblings().removeClass(className);
        });
    });
}
function highLightShow(el,index,className){
    $(el).eq(index).addClass(className).siblings().removeClass(className);
}
//获取宽度
function getWidth(el){
    var width=0;
    width+=pi($(el).css("width"))+pi($(el).css("padding-left"))+pi($(el).css("padding-right"));
    return width;
}
function getMargin(el){
    var margin=0;
    margin+=pi($(el).css("margin-left"))+pi($(el).css("margin-right"));
    return margin;
}
function getPadding(el){
    var padding=0;
    padding+=pi($(el).css("padding-left"))+pi($(el).css("padding-right"));
    return padding;
}
function getHeight(el){
    var height=0;
    height+=pi($(el).css("height"))+pi($(el).css("padding-top"))+pi($(el).css("padding-bottom"));
    return height;
}
function getWidth(el){
    var width=0;
    width+=pi($(el).css("width"))+pi($(el).css("padding-left"))+pi($(el).css("padding-right"));
    return width;
}
// 打印信息
function log(text){
    console.log(text);
}
//设置两个 元素一样高
function setHeight(el,targetEl) {
    document.querySelector(targetEl).style.minHeight=window.getComputedStyle(document.querySelector(el)).height;
}
//高亮导航标签
function highLightNav(number, el) {
    if (!el) {
        var el = "#nav .nav>li"
    }
    var nav = document.querySelectorAll(el);
    for (var i = 0; i < nav.length; i++) {
        if (i == number) {
            nav[i].setAttribute("class", "active");
            nav[i].style.backgroundColor = '#5eb91a';
        } else {
            nav[i].setAttribute("class", "");
            nav[i].style.backgroundColor = '#fff';
        }
    }
}
//原生标签页切换
function ysTabs(children, targetEl,className) {
    if(!className){className="current"}
    var tag = document.querySelectorAll(children); //获取Tag下的li，即Tag标签
    var content = document.querySelectorAll(targetEl); //获取Tag标签对应的内容
    content[0].style.display = "block"; //默认显示第一个标签的内容
    var len = tag.length;
    for (var i = 0; i < len; i++) {
        tag[i].index = i; //设置对象的INDEX属性，方便下面调用
        tag[i].onclick = function () {
            for (var n = 0; n < len; n++) {
                tag[n].className = "";
                content[n].style.display = "none";
            }
            tag[this.index].className = className;
            content[this.index].style.display = "block";
        }
    }
}